package leetcode_day._2021._202106._2130;

/**
 * @author yzh
 * @version 1.0
 * @date 2021/6/23 13:49
 * 二进制中1的个数
 * 算法：位运算
 */
public class _23_剑指offer15 {

    public int hammingWeight(int n) {
        int ans = 0;
        for (int i = 0; i < 32; i++) if ((n >> i & 1) == 1) ++ans;
        return ans;
    }

}
